import request from '../utils/request'
// import store from '@/store'

export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 频道 - 用户已选列表
export const channelAPI = () => request({
  url: '/v1_0/user/channels'
})

export const articlesListAPI = ({ channelId, timestamp }) => request({
  url: '/v1_0/articles',
  params: {
    channel_id: channelId,
    timestamp: timestamp || new Date().getTime() + ''
  }
})

export const articleDislikeAPI = ({ artId }) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target: artId
  }
})

export const articleReportAPI = ({ artId, type }) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target: artId,
    type: type,
    remark: type === '0' ? '其他问题---' : null
  }
})

// 频道 - 更新已选
export const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
    // 请求头在axios请求拦截器携带了
  })
}
export const suggestAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}

export const searchResultListAPI = ({ q, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q,
      page
    }
  })
}

export const articleDetaiAPI = ({ id }) => {
  return request({
    url: `/v1_0/articles/${id}`
  })
}
// 关注作者
export const followedUserAPI = ({ target }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}
// 取消关注
export const unFollowedUserAPI = ({ uid }) => {
  return request({
    url: `/v1_0/user/followings/${uid}`,
    method: 'DELETE'
  })
}
// 点赞文章
export const attitudeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target
    }
  })
}
// 取消点赞
export const unAttitudeAPI = ({ artId }) => {
  return request({
    url: `/v1_0/article/likings/${artId}`,
    method: 'DELETE'
  })
}

// 获取评论列表
export const commentListAPI = ({ artId, offset = null, limit }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset: offset,
      limit: limit
    }
  })
}

// 点赞评论
export const commentLikingAPI = ({ comId }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })
}
// 取消点赞评论
export const commentDisLikingAPI = ({ comId }) => {
  return request({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}
// 发布评论
export const commentIssueAPI = ({ artId, comText }) => {
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: comText
    }
  })
}
